
package com.huawei.saashousekeeper.config;

import lombok.extern.log4j.Log4j2;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.util.Map;

/**
 * 租户schema存储
 *
 * @since 2022-02-14
 */
@ConfigurationProperties(prefix = "spring.schema")
@RefreshScope
@Log4j2
public class TenantConfigurer {
    private Map<String, String> tenantMap;

    private boolean enabled;

    public Map<String, String> getTenantMap() {
        return tenantMap;
    }

    public void setTenantMap(Map<String, String> tenantMap) {
        this.tenantMap = tenantMap;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getSchema() {
        String schema = null;
        try {
            log.info("tenantDomain: " + TenantContext.get());
            schema = tenantMap.get(TenantContext.get());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        log.info("schema: " + schema);
        return schema;
    }
}
